<template>
	<view class="money-records-container">
		<!-- 余额概览 -->
		<view class="balance-overview">
			<view class="balance-card">
				<view class="balance-item">
					<text class="balance-amount">¥{{ model.amount }}</text>
					<text class="balance-label">余额</text>
				</view>
				<view class="balance-item">
					<text class="balance-amount available">¥{{ model.amount2 }}</text>
					<text class="balance-label">可提现</text>
				</view>
			</view>
			<view class="balance-actions">
				<text class="balance-note">余额记录</text>
				<view class="withdraw-btn-small" @click="handleWithdraw">
					<text class="withdraw-text-small">提现</text>
				</view>
			</view>
		</view>

		<!-- 记录列表 -->
		<view class="records-scroll">
			<view class="records-list">
				<view
					v-for="(record, index) in pageData.data"
					:key="record.id || index"
					class="record-item"
				>
					<view class="record-content">
						<view class="record-info">
							<text class="record-type">{{ record.note }}</text>
							<text class="record-date">{{ record.add_date }}</text>
						</view>
						<view class="record-amount">
							<text class="amount-text" :class="getAmountClass(record.amount)">
								{{ formatAmount(record.amount) }}
							</text>
							<text class="balance-after">¥{{ record.after_amount }}</text>
						</view>
					</view>
				</view>

				<!-- 空状态 -->
				<view v-if="pageData.data.length === 0 && !loading" class="empty-state">
					<image src="/static/logo.png" class="empty-icon" mode="aspectFit"></image>
					<text class="empty-text">暂无余额记录</text>
					<text class="empty-tip">快去参与一些活动赚取收益吧！</text>
				</view>

				<!-- 加载状态 -->
				<view v-if="status==='loading'" class="loading-state">
					<view class="loading-spinner"></view>
					<text class="loading-text">加载中...</text>
				</view>

				<!-- 没有更多 -->
				<view v-if="status==='noMore'" class="no-more">
					<view class="no-more-line"></view>
					<text class="no-more-text">已显示全部记录</text>
					<view class="no-more-line"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import {usePageData} from "../../common/usePageData";
import {ref} from 'vue'
import {useShowData} from "../../common/data";

const searchObject = ref({
	page: 1,
	size: 10,
	beginDate: null,
	endDate: null
})



const {data:model}=useShowData("my_money", {})

const { pageData, status, searchList, search, loading, loadMore } = usePageData("money_list", searchObject)


// 格式化金额显示
const formatAmount = (amount) => {
	if (amount > 0) {
		return `+${amount}`
	}
	return `${amount}`
}

// 获取金额样式类
const getAmountClass = (amount) => {
	if (amount > 0) {
		return 'amount-positive'
	} else if (amount < 0) {
		return 'amount-negative'
	}
	return 'amount-neutral'
}

// 处理提现操作
const handleWithdraw = () => {
	uni.navigateTo({
		url: '/pages/manager/cash'
	})
}

</script>

<style scoped>
.money-records-container {
	min-height: 100vh;
	background: #f8f9fa;
}

/* 余额概览样式 */
.balance-overview {
	background: linear-gradient(135deg, #AA0E99 0%, #D946EF 100%);
	padding: 40rpx 30rpx 25rpx;
	color: white;
	position: relative;
	overflow: hidden;
}

.balance-overview::before {
	content: '';
	position: absolute;
	top: -40%;
	right: -15%;
	width: 160rpx;
	height: 160rpx;
	background: rgba(255, 255, 255, 0.1);
	border-radius: 50%;
	z-index: 1;
}

.balance-overview::after {
	content: '';
	position: absolute;
	bottom: -25%;
	left: -8%;
	width: 120rpx;
	height: 120rpx;
	background: rgba(255, 255, 255, 0.08);
	border-radius: 50%;
	z-index: 1;
}

.balance-card {
	display: flex;
	justify-content: space-between;
	margin-bottom: 20rpx;
	position: relative;
	z-index: 2;
	gap: 16rpx;
}

.balance-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	background: rgba(255, 255, 255, 0.15);
	backdrop-filter: blur(10rpx);
	border-radius: 12rpx;
	padding: 18rpx 24rpx;
	flex: 1;
	box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.1);
}

.balance-amount {
	font-size: 42rpx;
	font-weight: 700;
	line-height: 1.1;
	margin-bottom: 4rpx;
}

.balance-amount.available {
	color: #FFE066;
}

.balance-label {
	font-size: 24rpx;
	opacity: 0.9;
	font-weight: 500;
}

.balance-note {
	font-size: 26rpx;
	font-weight: 600;
	text-align: center;
	position: relative;
	z-index: 2;
	opacity: 0.95;
}

.balance-actions {
	display: flex;
	justify-content: space-between;
	align-items: center;
	position: relative;
	z-index: 2;
}

.withdraw-btn-small {
	background: rgba(255, 255, 255, 0.2);
	border: 1rpx solid rgba(255, 255, 255, 0.3);
	border-radius: 16rpx;
	padding: 8rpx 30rpx;
	font-size: 24rpx;
	color: white;
	backdrop-filter: blur(10rpx);
	transition: all 0.3s ease;
	height: auto;
	line-height: 1.2;
}

.withdraw-btn-small:active {
	background: rgba(255, 255, 255, 0.3);
	transform: scale(0.95);
}

.withdraw-text-small {
	color: white;
	font-size: 24rpx;
	font-weight: 500;
}

/* 记录列表样式 */
.records-scroll {
	flex: 1;
	overflow-y: auto;
	padding-top: 20rpx;
}

.records-list {
	padding: 0 30rpx 30rpx;
}

.record-item {
	background: #fff;
	border-radius: 16rpx;
	margin-bottom: 16rpx;
	padding: 30rpx;
	box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
	transition: all 0.3s ease;
}

.record-item:active {
	transform: translateY(2rpx);
	box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}

.record-content {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.record-info {
	display: flex;
	flex-direction: column;
}

.record-type {
	font-size: 32rpx;
	font-weight: 500;
	color: #1a1a1a;
	line-height: 1.4;
}

.record-date {
	font-size: 24rpx;
	color: #999;
	margin-top: 8rpx;
}

.record-amount {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
}

.amount-text {
	font-size: 32rpx;
	font-weight: 600;
	line-height: 1.4;
}

.amount-positive {
	color: #4CAF50;
}

.amount-negative {
	color: #ff6b35;
}

.amount-neutral {
	color: #666;
}

.balance-after {
	font-size: 24rpx;
	color: #999;
	margin-top: 8rpx;
}

/* 空状态样式 */
.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 120rpx 40rpx;
	text-align: center;
}

.empty-icon {
	width: 120rpx;
	height: 120rpx;
	margin-bottom: 32rpx;
	opacity: 0.3;
}

.empty-text {
	font-size: 32rpx;
	color: #666;
	margin-bottom: 16rpx;
}

.empty-tip {
	font-size: 26rpx;
	color: #999;
	line-height: 1.5;
}

/* 加载状态样式 */
.loading-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60rpx 40rpx;
}

.loading-spinner {
	width: 60rpx;
	height: 60rpx;
	border: 4rpx solid #f3f3f3;
	border-top: 4rpx solid #667eea;
	border-radius: 50%;
	animation: spin 1s linear infinite;
	margin-bottom: 20rpx;
}

@keyframes spin {
	0% { transform: rotate(0deg); }
	100% { transform: rotate(360deg); }
}

.loading-text {
	font-size: 26rpx;
	color: #999;
}

/* 没有更多样式 */
.no-more {
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 40rpx;
}

.no-more-line {
	flex: 1;
	height: 1rpx;
	background: #e5e5e5;
}

.no-more-text {
	font-size: 24rpx;
	color: #999;
	margin: 0 20rpx;
}
</style>
